package common;

/**
 * @Author quan
 * @Description TODO
 * @Date 2023/7/4 11:01
 */

/**
 * 响应的时候以json的形式返回，这里定义一个共用的类
 */
public class AppResult<T> {
    //用于描述状态码的属性
    private int code;
    //描述信息
    private String message;
    //返回数据:泛型当类里面传的是User，后面data里面存的就是User
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    //三个参数的构造方法
    public AppResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    //工厂方法
    /**
     * 普通的成功方法
     * @return
     */
    public static AppResult success(){
        return new AppResult(0,"操作成功",null);
    }
    public static AppResult success(String message){
        return new AppResult(0,message,null);
    }
    public static <T>AppResult success(T data){
        return new AppResult(0,"操作成功",data);
    }
    public static <T>AppResult success(String message,T data){
        return new AppResult(0,message,data);
    }

    /**
     * 失败方法
     * @return
     */
    public static AppResult failed(){
        return new AppResult(1000,"操作失败",null);
    }
    public static AppResult failed(String message){
        return new AppResult(1000,message,null);
    }

}
